home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 359_09 / patch4.000 / LIB / BISON.SIM next >
Encoding:
Text File  |  1991-07-21  |  15.0 KB  |  609 lines

  1. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  2. #line 3 "bison.simple"
  3.  
  4. /* Skeleton output parser for bison,
  5.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. #ifndef alloca
  23. #ifdef __GNUC__
  24. #define alloca __builtin_alloca
  25. #else /* Not GNU C.  */
  26. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  27. #include <alloca.h>
  28. #else /* Not sparc */
  29. #ifdef MSDOS
  30. #include <malloc.h>
  31. #endif /* MSDOS */
  32. #endif /* Not sparc.  */
  33. #endif /* Not GNU C.  */
  34. #endif /* alloca not defined.  */
  35.  
  36. /* This is the parser code that is written into each bison parser
  37.   when the %semantic_parser declaration is not specified in the grammar.
  38.   It was written by Richard Stallman by simplifying the hairy parser
  39.   used when %semantic_parser is specified.  */
  40.  
  41. /* Note: there must be only one dollar sign in this file.
  42.    It is replaced by the list of actions, each action
  43.    as one case of the switch.  */
  44.  
  45. #define yyerrok        (yyerrstatus = 0)
  46. #define yyclearin    (yychar = YYEMPTY)
  47. #define YYEMPTY        -2
  48. #define YYEOF        0
  49. #define YYACCEPT    return(0)
  50. #define YYABORT     return(1)
  51. #define YYERROR        goto yyerrlab1
  52. /* Like YYERROR except do call yyerror.
  53.    This remains here temporarily to ease the
  54.    transition to the new meaning of YYERROR, for GCC.
  55.    Once GCC version 2 has supplanted version 1, this can go.  */
  56. #define YYFAIL        goto yyerrlab
  57. #define YYRECOVERING()  (!!yyerrstatus)
  58. #define YYBACKUP(token, value) \
  59. do                                \
  60.   if (yychar == YYEMPTY && yylen == 1)                \
  61.     { yychar = (token), yylval = (value);            \
  62.       yychar1 = YYTRANSLATE (yychar);                \
  63.       YYPOPSTACK;                        \
  64.       goto yybackup;                        \
  65.     }                                \
  66.   else                                \
  67.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  68. while (0)
  69.  
  70. #define YYTERROR    1
  71. #define YYERRCODE    256
  72.  
  73. #ifndef YYPURE
  74. #define YYLEX        yylex()
  75. #endif
  76.  
  77. #ifdef YYPURE
  78. #ifdef YYLSP_NEEDED
  79. #define YYLEX        yylex(&yylval, &yylloc)
  80. #else
  81. #define YYLEX        yylex(&yylval)
  82. #endif
  83. #endif
  84.  
  85. /* If nonreentrant, generate the variables here */
  86.  
  87. #ifndef YYPURE
  88.  
  89. int    yychar;            /*  the lookahead symbol        */
  90. YYSTYPE    yylval;            /*  the semantic value of the        */
  91.                 /*  lookahead symbol            */
  92.  
  93. #ifdef YYLSP_NEEDED
  94. YYLTYPE yylloc;            /*  location data for the lookahead    */
  95.                 /*  symbol                */
  96. #endif
  97.  
  98. int yynerrs;            /*  number of parse errors so far       */
  99. #endif  /* not YYPURE */
  100.  
  101. #if YYDEBUG != 0
  102. int yydebug;            /*  nonzero means print parse trace    */
  103. /* Since this is uninitialized, it does not stop multiple parsers
  104.    from coexisting.  */
  105. #endif
  106.  
  107. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  108.  
  109. #ifndef    YYINITDEPTH
  110. #define YYINITDEPTH 200
  111. #endif
  112.  
  113. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  114.     (effective only if the built-in stack extension method is used).  */
  115.  
  116. #if YYMAXDEPTH == 0
  117. #undef YYMAXDEPTH
  118. #endif
  119.  
  120. #ifndef YYMAXDEPTH
  121. #define YYMAXDEPTH 10000
  122. #endif
  123.  
  124. #ifndef __cplusplus
  125.  
  126. /* This is the most reliable way to avoid incompatibilities
  127.    in available built-in functions on various systems.  */
  128. static void
  129. __yy_bcopy (from, to, count)
  130.      char *from;
  131.      char *to;
  132.      int count;
  133. {
  134.   register char *f = from;
  135.   register char *t = to;
  136.   register int i = count;
  137.  
  138.   while (i-- > 0)
  139.     *t++ = *f++;
  140. }
  141.  
  142. #else /* __cplusplus */
  143.  
  144. /* This is the most reliable way to avoid incompatibilities
  145.    in available built-in functions on various systems.  */
  146. static void
  147. __yy_bcopy (char *from, char *to, int count)
  148. {
  149.   register char *f = from;
  150.   register char *t = to;
  151.   register int i = count;
  152.  
  153.   while (i-- > 0)
  154.     *t++ = *f++;
  155. }
  156.  
  157. #endif
  158.  
  159. #line 160 "bison.simple"
  160. int
  161. yyparse()
  162. {
  163.   register int yystate;
  164.   register int yyn;
  165.   register short *yyssp;
  166.   register YYSTYPE *yyvsp;
  167.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  168.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  169.  
  170.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  171.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  172.  
  173.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  174.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  175.  
  176. #ifdef YYLSP_NEEDED
  177.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  178.   YYLTYPE *yyls = yylsa;
  179.   YYLTYPE *yylsp;
  180.  
  181. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  182. #else
  183. #define YYPOPSTACK   (yyvsp--, yysp--)
  184. #endif
  185.  
  186.   int yystacksize = YYINITDEPTH;
  187.  
  188. #ifdef YYPURE
  189.   int yychar;
  190.   YYSTYPE yylval;
  191.   int yynerrs;
  192. #ifdef YYLSP_NEEDED
  193.   YYLTYPE yylloc;
  194. #endif
  195. #endif
  196.  
  197.   YYSTYPE yyval;        /*  the variable used to return        */
  198.                 /*  semantic values from the action    */
  199.                 /*  routines                */
  200.  
  201.   int yylen;
  202.  
  203. #if YYDEBUG != 0
  204.   if (yydebug)
  205.     fprintf(stderr, "Starting parse\n");
  206. #endif
  207.  
  208.   yystate = 0;
  209.   yyerrstatus = 0;
  210.   yynerrs = 0;
  211.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  212.  
  213.   /* Initialize stack pointers.
  214.      Waste one element of value and location stack
  215.      so that they stay on the same level as the state stack.  */
  216.  
  217.   yyssp = yyss - 1;
  218.   yyvsp = yyvs;
  219. #ifdef YYLSP_NEEDED
  220.   yylsp = yyls;
  221. #endif
  222.  
  223. /* Push a new state, which is found in  yystate  .  */
  224. /* In all cases, when you get here, the value and location stacks
  225.    have just been pushed. so pushing a state here evens the stacks.  */
  226. yynewstate:
  227.  
  228.   *++yyssp = yystate;
  229.  
  230.   if (yyssp >= yyss + yystacksize - 1)
  231.     {
  232.       /* Give user a chance to reallocate the stack */
  233.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  234.       YYSTYPE *yyvs1 = yyvs;
  235.       short *yyss1 = yyss;
  236. #ifdef YYLSP_NEEDED
  237.       YYLTYPE *yyls1 = yyls;
  238. #endif
  239.  
  240.       /* Get the current used size of the three stacks, in elements.  */
  241.       int size = yyssp - yyss + 1;
  242.  
  243. #ifdef yyoverflow
  244.       /* Each stack pointer address is followed by the size of
  245.      the data in use in that stack, in bytes.  */
  246.       yyoverflow("parser stack overflow",
  247.          &yyss1, size * sizeof (*yyssp),
  248.          &yyvs1, size * sizeof (*yyvsp),
  249. #ifdef YYLSP_NEEDED
  250.          &yyls1, size * sizeof (*yylsp),
  251. #endif
  252.          &yystacksize);
  253.  
  254.       yyss = yyss1; yyvs = yyvs1;
  255. #ifdef YYLSP_NEEDED
  256.       yyls = yyls1;
  257. #endif
  258. #else /* no yyoverflow */
  259.       /* Extend the stack our own way.  */
  260.       if (yystacksize >= YYMAXDEPTH)
  261.     {
  262.       yyerror("parser stack overflow");
  263.       return 2;
  264.     }
  265.       yystacksize *= 2;
  266.       if (yystacksize > YYMAXDEPTH)
  267.     yystacksize = YYMAXDEPTH;
  268.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  269.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  270.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  271.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  272. #ifdef YYLSP_NEEDED
  273.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  274.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  275. #endif
  276. #endif /* no yyoverflow */
  277.  
  278.       yyssp = yyss + size - 1;
  279.       yyvsp = yyvs + size - 1;
  280. #ifdef YYLSP_NEEDED
  281.       yylsp = yyls + size - 1;
  282. #endif
  283.  
  284. #if YYDEBUG != 0
  285.       if (yydebug)
  286.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  287. #endif
  288.  
  289.       if (yyssp >= yyss + yystacksize - 1)
  290.     YYABORT;
  291.     }
  292.  
  293. #if YYDEBUG != 0
  294.   if (yydebug)
  295.     fprintf(stderr, "Entering state %d\n", yystate);
  296. #endif
  297.  
  298.  yybackup:
  299.  
  300. /* Do appropriate processing given the current state.  */
  301. /* Read a lookahead token if we need one and don't already have one.  */
  302. /* yyresume: */
  303.  
  304.   /* First try to decide what to do without reference to lookahead token.  */
  305.  
  306.   yyn = yypact[yystate];
  307.   if (yyn == YYFLAG)
  308.     goto yydefault;
  309.  
  310.   /* Not known => get a lookahead token if don't already have one.  */
  311.  
  312.   /* yychar is either YYEMPTY or YYEOF
  313.      or a valid token in external form.  */
  314.  
  315.   if (yychar == YYEMPTY)
  316.     {
  317. #if YYDEBUG != 0
  318.       if (yydebug)
  319.     fprintf(stderr, "Reading a token: ");
  320. #endif
  321.       yychar = YYLEX;
  322.     }
  323.  
  324.   /* Convert token to internal form (in yychar1) for indexing tables with */
  325.  
  326.   if (yychar <= 0)        /* This means end of input. */
  327.     {
  328.       yychar1 = 0;
  329.       yychar = YYEOF;        /* Don't call YYLEX any more */
  330.  
  331. #if YYDEBUG != 0
  332.       if (yydebug)
  333.     fprintf(stderr, "Now at end of input.\n");
  334. #endif
  335.     }
  336.   else
  337.     {
  338.       yychar1 = YYTRANSLATE(yychar);
  339.  
  340. #if YYDEBUG != 0
  341.       if (yydebug)
  342.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  343. #endif
  344.     }
  345.  
  346.   yyn += yychar1;
  347.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  348.     goto yydefault;
  349.  
  350.   yyn = yytable[yyn];
  351.  
  352.   /* yyn is what to do for this token type in this state.
  353.      Negative => reduce, -yyn is rule number.
  354.      Positive => shift, yyn is new state.
  355.        New state is final state => don't bother to shift,
  356.        just return success.
  357.      0, or most negative number => error.  */
  358.  
  359.   if (yyn < 0)
  360.     {
  361.       if (yyn == YYFLAG)
  362.     goto yyerrlab;
  363.       yyn = -yyn;
  364.       goto yyreduce;
  365.     }
  366.   else if (yyn == 0)
  367.     goto yyerrlab;
  368.  
  369.   if (yyn == YYFINAL)
  370.     YYACCEPT;
  371.  
  372.   /* Shift the lookahead token.  */
  373.  
  374. #if YYDEBUG != 0
  375.   if (yydebug)
  376.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  377. #endif
  378.  
  379.   /* Discard the token being shifted unless it is eof.  */
  380.   if (yychar != YYEOF)
  381.     yychar = YYEMPTY;
  382.  
  383.   *++yyvsp = yylval;
  384. #ifdef YYLSP_NEEDED
  385.   *++yylsp = yylloc;
  386. #endif
  387.  
  388.   /* count tokens shifted since error; after three, turn off error status.  */
  389.   if (yyerrstatus) yyerrstatus--;
  390.  
  391.   yystate = yyn;
  392.   goto yynewstate;
  393.  
  394. /* Do the default action for the current state.  */
  395. yydefault:
  396.  
  397.   yyn = yydefact[yystate];
  398.   if (yyn == 0)
  399.     goto yyerrlab;
  400.  
  401. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  402. yyreduce:
  403.   yylen = yyr2[yyn];
  404.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  405.  
  406. #if YYDEBUG != 0
  407.   if (yydebug)
  408.     {
  409.       int i;
  410.  
  411.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  412.            yyn, yyrline[yyn]);
  413.  
  414.       /* Print the symboles being reduced, and their result.  */
  415.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  416.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  417.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  418.     }
  419. #endif
  420.  
  421. $   /* the action file gets copied in in place of this dollarsign */
  422. #line 423 "bison.simple"
  423.  
  424.   yyvsp -= yylen;
  425.   yyssp -= yylen;
  426. #ifdef YYLSP_NEEDED
  427.   yylsp -= yylen;
  428. #endif
  429.  
  430. #if YYDEBUG != 0
  431.   if (yydebug)
  432.     {
  433.       short *ssp1 = yyss - 1;
  434.       fprintf (stderr, "state stack now");
  435.       while (ssp1 != yyssp)
  436.     fprintf (stderr, " %d", *++ssp1);
  437.       fprintf (stderr, "\n");
  438.     }
  439. #endif
  440.  
  441.   *++yyvsp = yyval;
  442.  
  443. #ifdef YYLSP_NEEDED
  444.   yylsp++;
  445.   if (yylen == 0)
  446.     {
  447.       yylsp->first_line = yylloc.first_line;
  448.       yylsp->first_column = yylloc.first_column;
  449.       yylsp->last_line = (yylsp-1)->last_line;
  450.       yylsp->last_column = (yylsp-1)->last_column;
  451.       yylsp->text = 0;
  452.     }
  453.   else
  454.     {
  455.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  456.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  457.     }
  458. #endif
  459.  
  460.   /* Now "shift" the result of the reduction.
  461.      Determine what state that goes to,
  462.      based on the state we popped back to
  463.      and the rule number reduced by.  */
  464.  
  465.   yyn = yyr1[yyn];
  466.  
  467.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  468.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  469.     yystate = yytable[yystate];
  470.   else
  471.     yystate = yydefgoto[yyn - YYNTBASE];
  472.  
  473.   goto yynewstate;
  474.  
  475. yyerrlab:   /* here on detecting error */
  476.  
  477.   if (! yyerrstatus)
  478.     /* If not already recovering from an error, report this error.  */
  479.     {
  480.       ++yynerrs;
  481.  
  482. #ifdef YYERROR_VERBOSE
  483.       yyn = yypact[yystate];
  484.  
  485.       if (yyn > YYFLAG && yyn < YYLAST)
  486.     {
  487.       int size = 0;
  488.       char *msg;
  489.       int x, count;
  490.  
  491.       count = 0;
  492.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  493.         if (yycheck[x + yyn] == x)
  494.           size += strlen(yytname[x]) + 15, count++;
  495.       msg = (char *) xmalloc(size + 15);
  496.       strcpy(msg, "parse error");
  497.  
  498.       if (count < 5)
  499.         {
  500.           count = 0;
  501.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  502.         if (yycheck[x + yyn] == x)
  503.           {
  504.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  505.             strcat(msg, yytname[x]);
  506.             strcat(msg, "'");
  507.             count++;
  508.           }
  509.         }
  510.       yyerror(msg);
  511.       free(msg);
  512.     }
  513.       else
  514. #endif /* YYERROR_VERBOSE */
  515.     yyerror("parse error");
  516.     }
  517.  
  518. yyerrlab1:   /* here on error raised explicitly by an action */
  519.  
  520.   if (yyerrstatus == 3)
  521.     {
  522.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  523.  
  524.       /* return failure if at end of input */
  525.       if (yychar == YYEOF)
  526.     YYABORT;
  527.  
  528. #if YYDEBUG != 0
  529.       if (yydebug)
  530.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  531. #endif
  532.  
  533.       yychar = YYEMPTY;
  534.     }
  535.  
  536.   /* Else will try to reuse lookahead token
  537.      after shifting the error token.  */
  538.  
  539.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  540.  
  541.   goto yyerrhandle;
  542.  
  543. yyerrdefault:  /* current state does not do anything special for the error token. */
  544.  
  545. #if 0
  546.   /* This is wrong; only states that explicitly want error tokens
  547.      should shift them.  */
  548.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  549.   if (yyn) goto yydefault;
  550. #endif
  551.  
  552. yyerrpop:   /* pop the current state because it cannot handle the error token */
  553.  
  554.   if (yyssp == yyss) YYABORT;
  555.   yyvsp--;
  556.   yystate = *--yyssp;
  557. #ifdef YYLSP_NEEDED
  558.   yylsp--;
  559. #endif
  560.  
  561. #if YYDEBUG != 0
  562.   if (yydebug)
  563.     {
  564.       short *ssp1 = yyss - 1;
  565.       fprintf (stderr, "Error: state stack now");
  566.       while (ssp1 != yyssp)
  567.     fprintf (stderr, " %d", *++ssp1);
  568.       fprintf (stderr, "\n");
  569.     }
  570. #endif
  571.  
  572. yyerrhandle:
  573.  
  574.   yyn = yypact[yystate];
  575.   if (yyn == YYFLAG)
  576.     goto yyerrdefault;
  577.  
  578.   yyn += YYTERROR;
  579.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  580.     goto yyerrdefault;
  581.  
  582.   yyn = yytable[yyn];
  583.   if (yyn < 0)
  584.     {
  585.       if (yyn == YYFLAG)
  586.     goto yyerrpop;
  587.       yyn = -yyn;
  588.       goto yyreduce;
  589.     }
  590.   else if (yyn == 0)
  591.     goto yyerrpop;
  592.  
  593.   if (yyn == YYFINAL)
  594.     YYACCEPT;
  595.  
  596. #if YYDEBUG != 0
  597.   if (yydebug)
  598.     fprintf(stderr, "Shifting error token, ");
  599. #endif
  600.  
  601.   *++yyvsp = yylval;
  602. #ifdef YYLSP_NEEDED
  603.   *++yylsp = yylloc;
  604. #endif
  605.  
  606.   yystate = yyn;
  607.   goto yynewstate;
  608. }
  609.